<?php

	class fileDownload
	{
		var $fileType;
		var $fileName;

		function sfile($file,$file_bak=null,$head_redect=false)
		{
			if(!file_exists($file)){
				$file = $file_bak;
			}

			$etag = md5_file($file);
			header('Etag: '.$etag);

			if(isset($_SERVER['HTTP_IF_NONE_MATCH']) && $_SERVER['HTTP_IF_NONE_MATCH'] == $etag){
				header('HTTP/1.1 304 Not Modified',true,304);
				exit(0);
			}else{
				set_time_limit(0);
				header("Expires: " .$expires. " GMT");
				header("Cache-Control: public");
				session_cache_limiter('public');
				$this->sendfile($file);
			}
		}

		function sendfile($file)
		{
			$handle = fopen($file, "rb");
			while($buffer = fread($handle,102400))
			{
				echo $buffer;
				flush();
			}
			fclose($handle);
		}

		function httpHeader()
		{
			header('Content-type: '.$this->fileType);
			header("Content-type:application/octet-stream;charset=utf-8");
			header("Content-Type: application/force-download");
			header("Content-Disposition:attachment;filename=".$this->fileName);
		}
	}
?>